function _(e) {
  return new TextDecoder().decode(e)
}
export default class FeatureTable {
  buffer: any
  binOffset: any
  binLength: any
  header: any
  constructor(e, t, r, s) {
    ;(this.buffer = e), (this.binOffset = t + r), (this.binLength = s)
    let n = null
    if (0 !== r) {
      const s = new Uint8Array(e, t, r)
      n = JSON.parse(_(s))
    } else n = {}
    this.header = n
  }
  getKeys() {
    return Object.keys(this.header)
  }
  getData(e, t = null, r = null, s = null) {
    const n = this.header
    if (!(e in n)) return null
    const i = n[e]
    if (i instanceof Object) {
      if (Array.isArray(i)) return i
      {
        const { buffer: n, binOffset: o, binLength: a } = this,
          l = i.byteOffset || 0,
          c = i.type || s,
          h = i.componentType || r
        if ("type" in i && s && i.type !== s) throw new Error("FeatureTable: Specified type does not match expected type.")
        let u, d
        switch (c) {
          case "SCALAR":
            u = 1
            break
          case "VEC2":
            u = 2
            break
          case "VEC3":
            u = 3
            break
          case "VEC4":
            u = 4
            break
          default:
            throw new Error(`FeatureTable : Feature type not provided for "${e}".`)
        }
        const p = o + l,
          f = t * u
        switch (h) {
          case "BYTE":
            d = new Int8Array(n, p, f)
            break
          case "UNSIGNED_BYTE":
            d = new Uint8Array(n, p, f)
            break
          case "SHORT":
            d = new Int16Array(n, p, f)
            break
          case "UNSIGNED_SHORT":
            d = new Uint16Array(n, p, f)
            break
          case "INT":
            d = new Int32Array(n, p, f)
            break
          case "UNSIGNED_INT":
            d = new Uint32Array(n, p, f)
            break
          case "FLOAT":
            d = new Float32Array(n, p, f)
            break
          case "DOUBLE":
            d = new Float64Array(n, p, f)
            break
          default:
            throw new Error(`FeatureTable : Feature component type not provided for "${e}".`)
        }
        if (p + f * d.BYTES_PER_ELEMENT > o + a) throw new Error("FeatureTable: Feature data read outside binary body length.")
        return d
      }
    }
    return i
  }
}
